package day05.concurrent02;

import java.util.concurrent.Semaphore;

/**
 *  6.Semaphore 信号量
 */
public class Demo04 {
    public static void main(String[] args) throws Exception {
        Semaphore semaphore = new Semaphore(0);
        new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    System.out.println("火车来到车站");
                    System.out.println("火车申请通过车站");
                    semaphore.acquire();
                    System.out.println("火车通过车站");
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }).start();
        Thread.sleep(3000);
        System.out.println("车站释放火车");
        semaphore.release();
    }
}
